package tool.codescan.loggers;

import tool.data.FieldRecord;
import tool.data.ParameterRecord;
import tool.data.ResultStore;
import tool.data.TypeDefinition;
import static tool.data.FieldRecord.EScope.*;

	/**
	 * @author jwb09119
	 * @date 2013/11/22
	 * 
	 * This class stores the various data collected by visitors and collates it as required.
	 * Note that the information stored here is primarily about the use of Types.
	 * 
	 */

public class VariableAndParameterLogger {

	ResultStore storage;
	
	
	// Constructor
	public VariableAndParameterLogger(ResultStore dataStore) {

		storage = dataStore;
		
	}


	public void registerClassVariable(String name, TypeDefinition fullTypeName, boolean isArray,
	                                                                               int modifiers) {
		
		FieldRecord fr = new FieldRecord(name, fullTypeName, CLASS);
		fr.setIsArray(isArray);
		fr.setModifiers(modifiers);
		
		storage.addVariable(fr);
		
	}

	
	/**
	 * Registers a method parameter with the data store
	 * @param name - The name of the parameter
	 * @param typeName - The type of the parameter
	 * @param fullTypeName - The full package name of the type
	 * @param isArray - input true of the parameter is an array
	 * @param modifiers - modifiers for the parameter
	 */
	public void registerMethodParameter(String name, TypeDefinition fullTypeName, boolean isArray, 
	                                                                               int modifiers) {

		ParameterRecord pr = new ParameterRecord(name, fullTypeName);
		pr.setIsArray(isArray);
		
		storage.addParameter(pr);
		
	}


	/**
	 * Registers a method local variable with the data store
	 * @param name - The name of the variable
	 * @param typeName - The type of the variable
	 * @param fullTypeName - The full package name of the type
	 * @param isArray - input true of the variable is an array
	 * @param modifiers - modifiers for the variable
	 */
	public void registerMethodLocalVariable(String name, TypeDefinition fullTypeName, 
	                                                              boolean isArray, int modifiers) {
		
		FieldRecord fr = new FieldRecord(name, fullTypeName, METHOD);
		fr.setIsArray(isArray);
		fr.setModifiers(modifiers);
		
		storage.addVariable(fr);
		
	}
	
}
